package org.mnj07.struts.hello;

import com.opensymphony.xwork2.ActionSupport;

public class Login extends ActionSupport {

  private String userName;
 
  private String password;
 
  private String message;
 
  public Login(){
    //empty
  }

  public String execute() {
    StringBuilder sb = new StringBuilder();
    sb.append("User Name : " + getUserName());
    String p = getPassword();
    if(p != null){
      sb.append(", Password length= " + p.length());
    }
    setMessage(sb.toString());
    return SUCCESS;
  }
 
  public void validate() {
    if(getUserName().length() == 0){
      addFieldError("userName", "User Name is required");
    }
    else if(!getUserName().equals("Admin")){
      addFieldError("userName", getUserName() + " is an Invalid User");
    }
    if(getPassword().length() == 0){
      addFieldError("password", getText("password.required"));
    }
  }
 
  public String getUserName() {
    return userName;
  }

  public void setUserName(String userName) {
    this.userName = userName;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
    this.message = message;
  }
}


